#include "BaseButton.h"
#include <QPainter>
#include <QMouseEvent>

BaseButton::BaseButton(QWidget *parent) :
	BaseItem(parent),
	_normalImage(NULL),
	_pressedImage(NULL)
{
	_moveable = false;
}

void BaseButton::paintEvent(QPaintEvent* event)
{
	QPainter painter(this);

	if(_pressed){
		if(!_pressedImage){
			painter.setBrush(QBrush(QColor(120,120,120)));
			painter.drawRect(0,0,_width,_height);
		}
		else{
			painter.drawPixmap(0,0,_width,_height,*_pressedImage);
		}
	}
	else{
		if(!_normalImage){
			painter.setBrush(QBrush(QColor(50,50,50)));
			painter.drawRect(0,0,_width,_height);
		}
		else{
			painter.drawPixmap(0,0,_width,_height,*_normalImage);
		}
	}

	painter.end();
}

void BaseButton::mousePressEvent(QMouseEvent*event)
{
	_pressed = true;
	repaint();
}

void BaseButton::mouseReleaseEvent(QMouseEvent*event)
{
	_pressed = false;
	emit clicked();
	repaint();
}

void BaseButton::setImage(QPixmap* normal, QPixmap* pressed)
{
	_normalImage = normal;
	_pressedImage = pressed == NULL ? _normalImage : pressed;
}
